package com.github.postsanf.yinian.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.GridView;
import android.widget.ImageView;

import com.github.postsanf.yinian.R;
import com.github.postsanf.yinian.adapter.TimeMarksMorePicAdapter;
import com.github.postsanf.yinian.constants.ACTIONs;
import com.umeng.analytics.MobclickAgent;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

public class TimeMarksMorePicActivity extends AppCompatActivity implements Serializable {
    private ImageView iv_back;
    private GridView gv_more_pic;
    private List<String> coverPic = new ArrayList<>();
    private TimeMarksMorePicAdapter timeMarksMorePicAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_time_marks_more_pic);
        Intent intent = getIntent();
        if (intent != null) {
            coverPic = intent.getStringArrayListExtra("CoverPic");
        }
        initView();
    }

    private void initView() {
        iv_back = ((ImageView) findViewById(R.id.iv_back));
        gv_more_pic = ((GridView) findViewById(R.id.gv_more_pic));
        timeMarksMorePicAdapter = new TimeMarksMorePicAdapter(TimeMarksMorePicActivity.this, coverPic);
        gv_more_pic.setAdapter(timeMarksMorePicAdapter);
        iv_back.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                finish();
            }
        });
        closeActivity();
    }

    private void closeActivity() {
        timeMarksMorePicAdapter.setOnClickSelectedListener(new TimeMarksMorePicAdapter.OnClickSelectedListener() {
            @Override
            public void setOnClickSelectedListener(String url) {
                Intent intent = new Intent(ACTIONs.Selected);
                intent.putExtra("selected", url);
                sendBroadcast(intent);
                finish();
            }
        });
    }

    // 友盟统计
    public void onResume() {
        super.onResume();
        MobclickAgent.onPageStart(this.getClass().getSimpleName());
        MobclickAgent.onResume(this);
    }

    public void onPause() {
        super.onPause();
        MobclickAgent.onPageEnd(this.getClass().getSimpleName());
        MobclickAgent.onPause(this);
    }
}
